package com.gitee.wsl.collections.iterator

import com.gitee.wsl.base.Objects

/**
 * Provides an interleaved iteration over the elements contained in a
 * collection of Iterators.
 *
 *
 * Given two [Iterator] instances `A` and `B`, the
 * [.next] method on this iterator will switch between `A.next()`
 * and `B.next()` until both iterators are exhausted.
 *
 *
 * @param <E> the type of elements returned by this iterator.
 * @since 4.1
</E> */
//class ZippingIterator<E>(vararg iterators: Iterator<out E>) : Iterator<E> {
//    /** The [Iterator]s to evaluate.  */
//    private val iterators: Iterator<Iterator< E>>
//
//    /** The next iterator to use for next().  */
//    private var nextIterator: Iterator< E>? = null
//
//    /** The last iterator which was used for next().  */
//    private var lastReturned: Iterator< E>? = null
//
//    /**
//     * Constructs a new `ZippingIterator` that will provide
//     * interleaved iteration of the specified iterators.
//     *
//     * @param iterators  the array of iterators
//     * @throws NullPointerException if any iterator is null
//     */
//    init {
//        // create a mutable list to be able to remove exhausted iterators
//        val list= ArrayList<Iterator< E>>()
//        for (iterator in iterators) {
//            list.add(iterator)
//        }
//        this.iterators = FluentIterable.of(list).loop().iterator()
//    }
//
//    /**
//     * Constructs a new `ZippingIterator` that will provide
//     * interleaved iteration over the two given iterators.
//     *
//     * @param a  the first child iterator
//     * @param b  the second child iterator
//     * @throws NullPointerException if either iterator is null
//     */
//    constructor(a: Iterator< E>, b: Iterator< E>) : this(arrayOf<Iterator?>(a, b))
//
//    /**
//     * Constructs a new `ZippingIterator` that will provide
//     * interleaved iteration over the three given iterators.
//     *
//     * @param a  the first child iterator
//     * @param b  the second child iterator
//     * @param c  the third child iterator
//     * @throws NullPointerException if either iterator is null
//     */
//    constructor(
//        a: Iterator<out E?>?,
//        b: Iterator<out E?>?,
//        c: Iterator<out E?>?,
//    ) : this(arrayOf<Iterator?>(a, b, c))
//
//    /**
//     * Returns `true` if any child iterator has remaining elements.
//     *
//     * @return true if this iterator has remaining elements
//     */
//     override fun hasNext(): Boolean {
//        // the next iterator has already been determined
//        // this might happen if hasNext() is called multiple
//        if (nextIterator != null) {
//            return true
//        }
//
//        while (iterators.hasNext()) {
//            val childIterator: Iterator< E> = iterators.next()
//            if (childIterator.hasNext()) {
//                nextIterator = childIterator
//                return true
//            }
//            // iterator is exhausted, remove it
//            iterators.remove()
//        }
//        return false
//    }
//
//    /**
//     * Returns the next element from a child iterator.
//     *
//     * @return the next interleaved element
//     * @throws NoSuchElementException if no child iterator has any more elements
//     */
//    @Throws(NoSuchElementException::class)
//    override fun next(): E {
//        if (!hasNext()) {
//            throw NoSuchElementException()
//        }
//
//        val `val` = nextIterator!!.next()
//        lastReturned = nextIterator
//        nextIterator = null
//        return `val`
//    }
//
//    /**
//     * Removes the last returned element from the child iterator that produced it.
//     *
//     * @throws IllegalStateException if there is no last returned element, or if
//     * the last returned element has already been removed
//     */
//    public override fun remove() {
//        checkNotNull(lastReturned) { "No value can be removed at present" }
//        lastReturned.remove()
//        lastReturned = null
//    }
//}
